version 16.0
log using "C:\Users\mrg19\Dropbox\matt\publications\jop6\replication\anes2016_analysis.log", replace
#delimit ;

*     ***************************************************************** *;
*     ***************************************************************** *;
*       File-Name:      anes2016_analysis.do                            *;
*       Date:           May 14, 2022									*;
*       Author:         MG                                         		*;
*       Purpose:      	Replicate results for Block, Golder, and Golder	*;
*						"Evaluating Claims of Intersectionality"		*;
*						Journal of Politics								*;
* 	    Input File:     anes2016_small.dta       		                *;
*       Output File:    none			                                *;
*       Data Output:    none                                            *;             
*       Previous file:  					     						*;
*       Machine:        desktop/laptop                     				*;
*     ****************************************************************  *;
*     ****************************************************************  *;

*     ****************************************************************  *;
*        Load data                                                      *;
*     ****************************************************************  *;

use "C:\Users\mrg19\Dropbox\matt\publications\jop6\replication\anes2016_small.dta", clear;

*     ****************************************************************  *;
*           Variable description                  						*;
*     ****************************************************************  *;

desc;

*     ****************************************************************  *;
*       Drop respondents who are not white or black						*;
*     ****************************************************************  *;

keep if white==1 | black==1;

*     ****************************************************************  *;
*		Generate interaction term for gender and race					*;
*     ****************************************************************  *;

gen female_black = female*black;
gen female_white = female*white;
gen male_black = male*black;
gen male_white = male*white;

order respondent_id female male black white female_black female_white male_black male_white;

*     ****************************************************************  *;
*           Summary statistics											*;
*     ****************************************************************  *;

sum;

sum like_republican;
sum female;

*     ****************************************************************  *;
*     ****************************************************************  *;
*		Produce results from standard interaction model in Table 2		*;
*     ****************************************************************  *;
*     ****************************************************************  *;

regress like_republican female black female_black age;

*     ****************************************************************  *;
*     ****************************************************************  *;
*		Calculate reported effects										*;
*     ****************************************************************  *;
*     ****************************************************************  *;

*     ****************************************************************  *;
*		Effect of being female among Whites								*;
*     ****************************************************************  *;

lincom _b[female];

scalar women_whites = r(estimate);
di women_whites;

*     ****************************************************************  *;
*		Effect of being female among Blacks								*;
*     ****************************************************************  *;

lincom _b[female]+_b[female_black];

scalar women_blacks = r(estimate);
di women_blacks;

*     ****************************************************************  *;
*		Effect of being Black among men									*;
*     ****************************************************************  *;

lincom _b[black];

scalar blacks_men= r(estimate);
di blacks_men;

*     ****************************************************************  *;
*		Effect of being Black among women								*;
*     ****************************************************************  *;

lincom _b[black]+_b[female_black];

scalar blacks_women= r(estimate);
di blacks_women;

*     ****************************************************************  *;
*		Interaction effect 												*;
*     ****************************************************************  *;

lincom _b[female_black];

*     ****************************************************************  *;
*     ****************************************************************  *;
*		Create Figure 4 showing the conditional effects of gender and	*;
*		race on Republican support in the 2016 US presidential 			*;
*		elections.														*;
*     ****************************************************************  *;
*     ****************************************************************  *;

regress like_republican female black female_black age;

*     ****************************************************************  *;
*		Create a 5 x 2 matrix to store inputs for creating plot			*;
*     ****************************************************************  *;

matrix plot = J(5, 2, .);
matrix coln plot = estimate se;

*     ****************************************************************  *;
*		Obtain the point estimates and standard errors for the effects	*;
*		shown in Figure 4 and place them in the matrix					*;
*     ****************************************************************  *;

lincom _b[female_black];
matrix plot[1,1]=r(estimate);
matrix plot[1,2]=r(se);

lincom _b[female];
matrix plot[2,1]=r(estimate);
matrix plot[2,2]=r(se);

lincom _b[female]+_b[female_black];
matrix plot[3,1]=r(estimate);
matrix plot[3,2]=r(se);

lincom _b[black];
matrix plot[4,1]=r(estimate);
matrix plot[4,2]=r(se);

lincom _b[black]+_b[female_black];
matrix plot[5,1]=r(estimate);
matrix plot[5,2]=r(se);

*     ****************************************************************  *;
*		Produce the plot using coefplot									*;
*     ****************************************************************  *;

coefplot (matrix(plot[.,1]), se(plot[.,2]) offset(0) lwidth(thick) m(smcircle) 
		mfcolor("126 163 204") mlc("126 163 204") ciop(lcolor("126 163 204"))),  
		legend(off) xtitle("Effect Size", size(2.5)) levels(95) 
		xlab(-3 -2.5 -2 -1.5 -1 -0.5 0 0.5, tlcolor(black) labcolor(black) labsize(2.5))    				
		coeflabels(r1="Interaction Effect for Gender and Race" 
		r2="Effect of being Female among Whites" r3="Effect of being Female among Blacks"  		
		r4="Effect of being Black among men" r5="Effect of being Black among women", 
		tlcolor(black) labcolor(black) labsize(2.5)) 
		yscale(noline) xscale(noline) mlabel format(%9.2f) mlabposition(12) 
		mlabgap(*2) mlabsize(2.5)  xline(0, lcolor(gray)) scheme(burd);
		
graph export "C:\Users\mrg19\Dropbox\matt\publications\jop6\replication\fig4.pdf", replace;

*     ****************************************************************  *;
*     ****************************************************************  *;
*		Calculate the values that go into Figure 5. These values show	*;
*		the predicted values and the conditional effects of gender and	*;
*		race on Republican support in the 2016 US presidential 			*;
*		elections.														*;
*     ****************************************************************  *;
*     ****************************************************************  *;

*     ****************************************************************  *;
*     ****************************************************************  *;
*		Start with the predicted values in the gray square.				*;
*     ****************************************************************  *;
*     ****************************************************************  *;

*     ****************************************************************  *;
*		40 year old White male											*;
*     ****************************************************************  *;

margins, at(female=0 black=0 female_black=0 age=40);

lincom _b[_cons]+40*_b[age];
scalar white_man40= r(estimate);
di white_man40;

*     ****************************************************************  *;
*		40 year old White female										*;
*     ****************************************************************  *;

margins, at(female=1 black=0 female_black=0 age=40);

lincom _b[_cons]+_b[female]+40*_b[age];
scalar white_woman40= r(estimate);
di white_woman40;

*     ****************************************************************  *;
*		40 year old Black male											*;
*     ****************************************************************  *;

margins, at(female=0 black=1 female_black=0 age=40);

lincom _b[_cons]+_b[black]+40*_b[age];
scalar black_man40= r(estimate);
di black_man40;

*     ****************************************************************  *;
*		40 year old Black female										*;
*     ****************************************************************  *;

margins, at(female=1 black=1 female_black=1 age=40);

lincom _b[_cons]+_b[female]+_b[black]+_b[female_black]+40*_b[age];
scalar black_woman40= r(estimate);
di black_woman40;

*     ****************************************************************  *;
*     ****************************************************************  *;
*		Now calculate the differences in predicted values. These 		*;
*		differences provide the other values in Figure 5. They are the	*;
*		the same as the effects calculated previously.					*;
*     ****************************************************************  *;
*     ****************************************************************  *;

*     ****************************************************************  *;
*		Effect of female among Whites or difference between White women *;
*		White men														*;
*     ****************************************************************  *;

lincom (_b[_cons]+_b[female]+40*_b[age])-(_b[_cons]+40*_b[age]);

lincom _b[female];

*     ****************************************************************  *;
*		Effect of female among Blacks or difference between Black women	*;
*		and Black men													*;
*     ****************************************************************  *;

lincom (_b[_cons]+_b[female]+_b[black]+_b[female_black]+40*_b[age])-(_b[_cons]+_b[black]+40*_b[age]);

lincom _b[female]+_b[female_black];

*     ****************************************************************  *;
*		Effect of being Black among men	or difference between Black men	*;
*		and White men													*;
*     ****************************************************************  *;

lincom (_b[_cons]+_b[black]+40*_b[age])-(_b[_cons]+40*_b[age]);

lincom _b[black];

*     ****************************************************************  *;
*		Effect of being Black among women or difference between Black	*;
*		women and White women											*;
*     ****************************************************************  *;

lincom (_b[_cons]+_b[female]+_b[black]+_b[female_black]+40*_b[age])-(_b[_cons]+_b[female]+40*_b[age]);

lincom _b[black]+_b[female_black];

*     ****************************************************************  *;
*		Interaction effect 												*;
*     ****************************************************************  *;

* Difference between (i) the difference between Black women and White women and (ii) the difference between Black men and White men;  

lincom ((_b[_cons]+_b[female]+_b[black]+_b[female_black]+40*_b[age])-(_b[_cons]+_b[black]+40*_b[age]))-((_b[_cons]+_b[female]+40*_b[age])-(_b[_cons]+40*_b[age]));

* Difference between (i) the difference between Black women and Black men and (ii) the difference between White women and White men; 

lincom ((_b[_cons]+_b[female]+_b[black]+_b[female_black]+40*_b[age])-(_b[_cons]+_b[black]+40*_b[age]))-((_b[_cons]+_b[female]+40*_b[age])-(_b[_cons]+40*_b[age]));

* interaction term coefficient;

lincom _b[female_black];

*     ****************************************************************  *;
*     ****************************************************************  *;
*		Calculate the substantive effects reported in the paper.		*;
*     ****************************************************************  *;
*     ****************************************************************  *;

*     ****************************************************************  *;
*		Effect of being female among whites								*;
*     ****************************************************************  *;

di (women_whites/white_man40)*100;

*     ****************************************************************  *;
*		Effect of being female among blacks								*;
*     ****************************************************************  *;

di (women_blacks/black_man40)*100;

*     ****************************************************************  *;
*		Effect of being black among men									*;
*     ****************************************************************  *;

di (blacks_men/white_man40)*100;

*     ****************************************************************  *;
*		Effect of being black among women								*;
*     ****************************************************************  *;

di (blacks_women/white_woman40)*100;

*     ****************************************************************  *;
*		Interaction effect 												*;
*     ****************************************************************  *;

di women_blacks/women_whites;

di blacks_women/blacks_men;

*     ****************************************************************  *;
*     ****************************************************************  *;
*		Show that effects and predicted values are identical if we use	*;
*		the alternative interaction model								*;
*     ****************************************************************  *;
*     ****************************************************************  *;

regress like_republican female_white male_black female_black age;

*     ****************************************************************  *;
*		Interaction effect												*;
*     ****************************************************************  *;

lincom _b[female_black]-_b[female_white]-_b[male_black];

*     ****************************************************************  *;
*		Effect of being female among Whites								*;
*     ****************************************************************  *;

lincom _b[female_white];

*     ****************************************************************  *;
*		Effect of being female among Blacks								*;
*     ****************************************************************  *;

lincom _b[female_black]-_b[male_black];

*     ****************************************************************  *;
*		Effect of being Black among men									*;
*     ****************************************************************  *;

lincom _b[male_black];

*     ****************************************************************  *;
*		Effect of being Black among women								*;
*     ****************************************************************  *;

lincom _b[female_black]-_b[female_white];

*     ****************************************************************  *;
*     ****************************************************************  *;
*		Predicted values based on the alternative interaction model  	*;
*     ****************************************************************  *;
*     ****************************************************************  *;

*     ****************************************************************  *;
*		40 year old White male											*;
*     ****************************************************************  *;

lincom _b[_cons]+40*_b[age];

*     ****************************************************************  *;
*		40 year old White female										*;
*     ****************************************************************  *;

lincom _b[_cons]+_b[female_white]+40*_b[age];

*     ****************************************************************  *;
*		40 year old Black male											*;
*     ****************************************************************  *;

lincom _b[_cons]+_b[male_black]+40*_b[age];

*     ****************************************************************  *;
*		40 year old Black female										*;
*     ****************************************************************  *;

lincom _b[_cons]+_b[female_black]+40*_b[age];

*     ****************************************************************  *;
*     ****************************************************************  *;
*		Show that our analysis is robust to including additional 		*;
*		controls for education and income.								*;
*     ****************************************************************  *;
*     ****************************************************************  *;

regress like_republican female black female_black age highschool undergrad grad income;

*     ****************************************************************  *;
*     ****************************************************************  *;
*		Replication Complete											*;
*     ****************************************************************  *;
*     ****************************************************************  *;

log close;

clear;

